//
//  NSString+Additions.m
//  OrderSeat
//
//  Created by wangwei on 13-10-14.
//  Copyright (c) 2013年 wangwei. All rights reserved.
//

#import "NSString+Additions.h"

@implementation NSString (Additions)

- (NSDate *)toDateWithStr:(NSString *)dateStr
{
    NSDateFormatter *inputFormatter = [[NSDateFormatter alloc] init];
    [inputFormatter setDateFormat:@"yyyy-MM-dd"];
    NSDate* inputDate = [inputFormatter dateFromString:dateStr];
    
    return inputDate;
}

- (CGSize)sizeWithSystemFontSize:(CGFloat)fontSize
{
    return [self sizeWithFont:[UIFont systemFontOfSize:fontSize]];
}

- (CGSize)sizeWithBoldFontSize:(CGFloat)fontSize
{
    return [self sizeWithFont:[UIFont boldSystemFontOfSize:fontSize]];
}

- (NSString*)encodeURL
{
    NSString *newString = NSMakeCollectable(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)self, NULL, CFSTR(":/?#[]@!$ &'()*+,;=\"<>%{}|\\^~`"), CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding)));
	if (newString) {
		return newString;
	}
    return @"";
}

+ (NSString*)encodeURL:(NSString *)string
{
    NSString *newString = NSMakeCollectable(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)string, NULL, CFSTR(":/?#[]@!$ &'()*+,;=\"<>%{}|\\^~`"), CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding)));
	if (newString) {
		return newString;
	}
    return @"";
}

@end
